#ifndef     __APP_H_INCLUDED__
#define     __APP_H_INCLUDED__

#include    "logger.h"

#define     RUN_APP(APPCLASS) int main(int argc, char * argv[]) { return APPCLASS().Run(argc, argv); }

/**
 * Simple application module
 */
class App {
public:
    App();
    virtual ~App() {}

    /**
     * Run this application
     * 
     * \param argc Command line argument count
     * \param argv Command line arguments
     * \return exit code
     */
    int Run(int argc, char * argv[]);

    /**
     * Local frame update rate
     * 
     * \param fps Frame count per second
     */
    void LockFPS(int fps) { if (fps > 0) _frame_time = 1000.0 / fps; }

    /**
     * Stop this application with given signal code
     * 
     * \param code Signal code to quit this application
     */
    void Stop(int code);

    /**
     * Initialization for this application.
     * 
     * \param argc Command line arguments' number
     * \param argv Command line arguments
     * \return Should we stop this application?
     */
    virtual bool OnInit(int argc, char * argv[]) { return true; }

    /**
     * Frame update
     */
    virtual void OnBreath() {}

    /**
     * Exit callback
     */
    virtual void OnExit() { LOG_INFO("Application exit with code : %d", _exit_code); }

protected:
    bool _running;
    int _exit_code;
    double _frame_time;
};

#endif//!   __APP_H_INCLUDED__